﻿@model ConferenceMasterModel
@{
	ViewBag.Title = Resources.ConferenceNotice + ConstValues.strDash + ViewBag.ConferenceName;
}
<div class="con" style="min-height:calc(100vh - 100px);overflow:auto">
	<div class="box clearfix">
		<div class="ftsy">
			<form id="frmDetail" method="post" enctype="multipart/form-data">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.ConferenceName：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="hidID" name="Id" type="hidden" />
							<input id="txtConferenceName" name="ConferenceName" class="easyui-textbox" style="height:27px; width:88%;" data-options="required:true" disabled="disabled" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.ConferenceNickName：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtConferenceNickName" name="ConferenceNickName" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true, validType:['length[1,20]']" disabled="disabled" />
						</td>
						<td style="text-align: right;" class="w1 c3">@Resources.OperateTime：</td>
						<td style="text-align: left;" class="w2 c4">
							<input id="txtOperateTime" name="OperateTime" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.OperateLocation：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtOperateLocation" name="OperateLocation" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true, validType:['length[1,100]']" />
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.ConferenceAddress：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtConferenceAddress" name="ConferenceAddress" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true, validType:['length[1,100]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Sponsor：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input id="txtSponsor" name="Sponsor" class="easyui-textbox" style="height:27px; width:88%;" data-options="required:true, prompt:'@Resources.SponsorPrompt',validType:['length[1,200]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right; " class="w1 c1">@Resources.ConferenceHomePageUrl：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtHomePageUrl" name="HomePageUrl" class="easyui-textbox" style="height:27px; width:88%;" data-options="prompt:'@Resources.Example http://www.htcis.net',validType:['length[1,100]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.Supporter：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input id="txtSupporter" name="Supporter" class="easyui-textbox" style="height:27px; width:88%;" data-options="required:true, validType:['length[1,100]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Contact：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtContact" name="Contact" class="easyui-textbox" style="height:27px; width:88%;" data-options="required:true, prompt:'@Resources.ContactPrompt',required:true, validType:['length[1,100]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.ContactPhone：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input id="txtContactPhone" name="ContactPhone" class="easyui-textbox" style="height:27px; width:88%;" data-options="required:true, prompt:'@Resources.ContactPrompt',required:true, validType:['length[1,100]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.ContactMail：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input id="txtContactMail" name="ContactMail" class="easyui-textbox" style="height:27px; width:88%;" data-options="required:true, prompt:'@Resources.ContactPrompt',required:true, validType:['length[1,100]']" />
						</td>
					</tr>
					<tr>
						<td style="text-align: right; " class="w1 c3">@Resources.PicForStamp：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input id="picForStamp" name="PicForStampFile" class="easyui-filebox" style="height:27px; width:77%;" data-options="prompt:'@Resources.UploadPicForPC', buttonText:'@Resources.ChoosePicForPC', accept: 'image/jpeg,image/png,image/gif'" />&nbsp;500*500&nbsp;&nbsp;&nbsp;&nbsp;
							<input type="hidden" id="hidPicForStamp" name="PicForStampFilePath" />
							<a href="javascript:void(0)" class="easyui-linkbutton" onclick='$("#picForStamp").filebox("clear"); $("#hidPicForStamp").val("");'>@Resources.Clear</a>
						</td>
					</tr>
					<tr>
						<td style="text-align: right; " class="w1 c1">@Resources.CustomDefinition：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input type=hidden id="txtCustomDefinition" name="CustomDefinition" />
							<div class="grid-container">
								<div class="grid-width-100" style="padding-left:0%;padding-right:0%;width:88%;">
									<textarea id="editor" name="editor"></textarea>
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td style="text-align: right; " class="w1 c3">
							<input type="checkbox" id="hasAttachment" name="HasAttachment" />
						</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">@Resources.HasAttachment</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.Id) || Utility.HasConferenceRole((User as ICISPrincipal), Model.Id, ConstValues.FunctionId.ConferenceNotice, RoleType.修改))
				{
				<text>
					<input type="button" id="saveBtn" class="gbtn" onclick="saveData();" value=@Resources.Save />&nbsp; &nbsp;
				</text>
				}
				<input type="button" class="rbtn" onclick="javascript: history.back(-1);" value=@Resources.Back />&nbsp;&nbsp;
				<input type="button" class="lbtn" onclick="noticePreview();" value=@Resources.NoticePreview />&nbsp;&nbsp;
				<input type="button" class="sbtn" value=@Resources.Help />&nbsp;&nbsp;
			</div>
		</div>
	</div>
</div>

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceNotice");
	common.setCurrentParentMenu("#menu_a2");

	var language = "@ViewBag.Language";
	if (language == "@ConstValues.Language.Cn") {
		CKEDITOR.config.language = "zh-cn";
	} else {
		CKEDITOR.config.language = "en";
	}

	initSample();

	$(function () {
		var id = "@Model.Id";
		var url = "@Url.Action(nameof(ConferenceNoticeController.GetEditData),
				nameof(ConferenceNoticeController).GetControllerName())" + "/" + id + "?random=" + Math.random();

		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
			} else {
				$("#detailWindowTitle").text("@Resources.Edit");
				$("#hidID").val(id);
				$("#txtConferenceName").textbox("setValue", data.data.conferenceName);
				$("#txtConferenceNickName").textbox("setValue", data.data.conferenceNickName);
				$("#txtOperateTime").textbox("setValue", data.data.operateTime);
				$("#txtOperateLocation").textbox("setValue", data.data.operateLocation);
				$("#txtConferenceAddress").textbox("setValue", data.data.conferenceAddress);
				$("#txtSponsor").textbox("setValue", data.data.sponsor);
				$("#txtHomePageUrl").textbox("setValue", data.data.homePageUrl);
				$("#txtSupporter").textbox("setValue", data.data.supporter);
				$("#txtContact").textbox("setValue", data.data.contact);
				$("#txtContactPhone").textbox("setValue", data.data.contactPhone);
				$("#txtContactMail").textbox("setValue", data.data.contactMail);
				$("#picForStamp").filebox("clear");
				$("#picForStamp").filebox("setText", data.data.picForStamp);
				$("#hidPicForStamp").val(data.data.picForStamp);
				CKEDITOR.instances.editor.setData(data.data.customDefinition);
				$("#hasAttachment").prop("checked", data.data.hasAttachment);
			}
		});
	});

	function saveData() {
		var isValid = $("#frmDetail").form("validate");

		if (isValid) {
			var picForStamp = $("#picForStamp").filebox("getText");
			if (picForStamp != "" && !/\.(gif|jpg|jpeg|png|GIF|JPG|PNG|JPEG)$/.test(picForStamp)) {
				common.showError("@Resources.MsgImgType");
				return false;
			}

			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0, {
						shade: [0.4, "#fff"]
					});

					$("#frmDetail").form({
						iframe: false,
						success: function (data) { }
					});

					$("#txtCustomDefinition").val(CKEDITOR.instances.editor.getData());
					$("#frmDetail").form("submit", {
						url: "@Url.Action(nameof(ConferenceNoticeController.Edit), nameof(ConferenceNoticeController).GetControllerName(),
								new { ConferenceId = Model.Id })",
						onSubmit: function (param) {
							param.random = Math.random();
						},
						success: function (data) {
							layer.close(loading);
							data = JSON.parse(data);
							if (data.result == "@ConstValues.AjaxFailResult") {
								common.showError(data.message);
							} else {
								common.showSuccess(data.message, true);
								setTimeout(function () {
									window.location.reload();
								}, 2000);
							}
						}
					});
				}
			});
		}
	}

	function noticePreview() {
		var isValid = $("#frmDetail").form("validate");

		if (isValid) {
			var picForStamp = $("#picForStamp").filebox("getText");
			if (picForStamp != "" && !/\.(gif|jpg|jpeg|png|GIF|JPG|PNG|JPEG)$/.test(picForStamp)) {
				common.showError("@Resources.MsgImgType");
				return false;
			}

			$("#txtCustomDefinition").val(CKEDITOR.instances.editor.getData());

			$("#frmDetail").form({
				iframe: false,
				success: function (data) { }
			});

			$("#frmDetail").form("submit", {
				url: "@Url.Action(nameof(ConferenceNoticeController.Edit), nameof(ConferenceNoticeController).GetControllerName(),
						new { ConferenceId = Model.Id })",
				onSubmit: function (param) {
					param.random = Math.random();
				},
				success: function (data) {
					doPreview();
				}
			});
		}
	}

	function doPreview() {
		$("#frmDetail").form({
			iframe: false,
			success: function (data) { }
		});

		$("#frmDetail").form("submit", {
			url: "@Url.Action(nameof(ConferenceNoticeController.Preview), nameof(ConferenceNoticeController).GetControllerName(),
					new { ConferenceId = Model.Id })",
			onSubmit: function (param) {
				param.random = Math.random();
			},
			success: function (data) {
				data = JSON.parse(data);
				var newWindow = window.open(data.data.replace("~", ""));
				setTimeout(function () {
					newWindow.document.title = "@Resources.NoticePreview";
				}, 100);
			}
		});
	}
</script>
}